import pygame
import constants as c
from os import path
import funs


def main_menu(screen):
    pygame.mixer.music.load(path.join(c.sound_folder, 'menu.ogg'))
    pygame.mixer.music.play(-1)
    title = pygame.image.load(path.join(c.img_dir, 'main.png'))
    title = pygame.transform.scale(title, (c.WIDTH, c.HEIGHT))
    screen.blit(title, (0, 0))
    pygame.display.update()
    while True:
        event = pygame.event.poll()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RETURN:
                break
        elif event.type == pygame.QUIT:
            pygame.quit()
            quit()
        else:
            funs.draw_text(screen, 'Press [Enter] to begin', 30,c.WIDTH/2, c.HEIGHT/2)
            funs.draw_text(screen, '[W]↑', 30, c.WIDTH/2, 2*c.HEIGHT/3-40)
            funs.draw_text(screen, '[A] ←  [S] ↓  [D] →', 30, c.WIDTH/2, 2*c.HEIGHT/3)
            pygame.display.update()

    ready = pygame.mixer.Sound(path.join(c.sound_folder, 'getready.ogg'))
    ready.play()

    screen.fill(c.BLACK)
    funs.draw_text(screen, 'GET READY',40, c.WIDTH/2, c.HEIGHT/3)
    pygame.display.update()
    

def menu_display(screen):
    main_menu(screen)
    pygame.time.wait(3000)
    pygame.mixer.music.stop()
    sounds_file = path.join(c.sound_folder, 'tgfcoder-FrozenJam-SeamlessLoop.ogg')
    pygame.mixer.music.load(sounds_file)
    pygame.mixer.music.play(-1)
